from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime, date

scheduler = BlockingScheduler(timezone='Asia/Shanghai')
def job():
    print(datetime.now().strftime("%Y-%m-%d %H:%M:%S")," 执行任务了")
def happy_new_year():
    print("新年快乐")
scheduler.add_job(happy_new_year, 'date', run_date=datetime(2022, 1, 1, 0, 0, 0)) # 在2022年元旦发邮件
scheduler.add_job(job, 'interval',  seconds=5) # 从现在开始每隔5秒运行一次
scheduler.add_job(job, 'cron', day_of_week='1-5', hour=12, minute=35) # 在周一到周五的12时35分运行一次
scheduler.start()
